home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / misc / egs.lha / EGS / EGS_Devels / Examples / EGS_Requester / requester1.c < prev    next >
C/C++ Source or Header  |  1993-02-17  |  3KB  |  202 lines

  1. /*
  2. **  Author: Markus van Kempen
  3. **  Date  : 18. Dezember 1992
  4. **          09 Jan 1993 mvk
  5. **
  6. **  This example shows how to work with EGS_REQUESTER.
  7. **
  8. **  The routines myError, myMSG and EventLoop open
  9. **
  10. **  requesters.
  11. **
  12. **
  13. **
  14. **  (c) by VIONA-Development 1992/93
  15. **
  16. */
  17.  
  18.  
  19. /*
  20. ** Init-Routines
  21. */
  22.  
  23. #include "Global.h"
  24. #include "EventLoop.c"
  25. #include "makegadget.c"
  26.  
  27. /*
  28. **
  29. **
  30. */
  31.  
  32. BOOL InitLibraries(struct OpenStructTyp *OS)
  33. {
  34.  struct OpenStructTyp *p = &OS[0];
  35.  
  36.  while (p->Base != NULL)
  37.  {
  38.    if ((*(p->Base) = (ULONG)OpenLibrary(p->Name,p->Version)) == NULL)
  39.        {
  40.            printf(" Can't open %s version %d",p->Name, p->Version);
  41.            return FALSE;
  42.        }
  43.        else
  44.        {  p ++; }
  45.  }
  46.    return TRUE;
  47. }
  48. /**/
  49.  
  50. /*
  51. **
  52. **
  53. */
  54.  
  55. void CloseLibraries(struct OpenStructTyp *OS)
  56. {
  57.  struct OpenStructTyp *p = &OS[0];
  58.  
  59.  while (*(p->Base) != NULL && p->Name != NULL)
  60.  {
  61.         CloseLibrary((void *)(*(p->Base)));
  62.         *(p->Base) = NULL;
  63.         p++;
  64.  }
  65. }
  66. /**/
  67.  
  68.  
  69. /*
  70. **  Open a requester in the middle of
  71. **  the screen.
  72. **
  73. */
  74.  
  75. void myMSG(char *string)
  76. {
  77.   if ( string != NULL)
  78.   {
  79.      if ( EGSRequestBase == NULL)
  80.       {
  81.           printf("%s\n",string);
  82.  
  83.       }else{
  84.  
  85.          ErrorReq = (ER_SimpleRequestPtr)ER_CreateSimpleRequest(NULL,
  86.                                           (char *)string,(char *)"OK");
  87.  
  88.          /*
  89.      **  Open requester in the middle of the screen,
  90.          **
  91.      **  if you can!
  92.          */
  93.  
  94.          ErrorReq->Req.Nw->Flags |= EI_WINDOWCENTER;
  95. /*
  96.          ErrorReq->Req.Nw->LeftEdge = Window->LeftEdge;
  97.          ErrorReq->Req.Nw->TopEdge  = Window->TopEdge;
  98. */
  99.          ErrorReq->Req.Title        ="Msg Requester";
  100.          ER_DoRequest(&(ErrorReq->Req)) ;
  101.       }
  102.   }
  103. }
  104.  
  105. /*
  106.  * Author: Markus van Kempen
  107.  * Date  : 9. November 92
  108.  *
  109.  * This routine is for error handling.
  110.  * It closes all open things of the
  111.  * program.
  112.  *
  113.  * if ende == TRUE then myError terminates,
  114.  *            otherwise it returns
  115.  *
  116.  */
  117. void myError(char *string,int ende)
  118. {
  119.  
  120.   myMSG("Hello world !|This is a Requester !");
  121.  
  122.   myMSG(string);
  123.  
  124.   if ( Window != NULL )
  125.      EI_CloseWindow(Window);
  126.  
  127.   if ( con != NULL )
  128.     EB_DeleteGadContext(con);
  129.  
  130.   if ( FontforMenu != NULL )
  131.     EG_CloseFont(FontforMenu);
  132.  
  133.   if ( Menu != NULL )
  134.     EI_FreeMenu(Menu);
  135.  
  136.   if ( ErrorReq != NULL )
  137.      ER_DeleteRequest(&(ErrorReq->Req));
  138.  
  139.   CloseLibraries(OpenStruct);
  140.  
  141.   if (ende)
  142.        exit(0);
  143.  
  144. }
  145. /**/
  146.  
  147.  
  148. /*
  149. **  myopen  = Opens all egs libraries
  150. **            and calls InitMenu from initmenu.c,
  151. **            then calls CreateGads from makegadgets.c
  152. **
  153. **
  154. */
  155.  
  156. struct EI_Window *myopen(void)
  157. {
  158. struct EI_Window     *fenster=NULL;
  159.  
  160.       if ( InitLibraries(OpenStruct) == FALSE)
  161.           myError("Can't OpenLibrary",10);
  162.  
  163.  
  164. /*
  165.           SEE Init_Menu.c
  166.  
  167.       Menu=InitMenu(FontforMenu);
  168.  
  169.  
  170.       if ( Menu == NULL )
  171.       myError("Could not build menu",10);
  172.  
  173. */
  174.  
  175.       fenster=CreateGads(NULL);
  176.  
  177.      if (fenster == NULL)
  178.                    myError("Could not open window",10);
  179.   return(fenster);
  180. }
  181.  
  182.  
  183. /*
  184. **
  185. **   start GUI
  186. **
  187. */
  188.  
  189. void main(void)
  190. {
  191.          Window=myopen();    /* see myopen.c */
  192.  
  193.          if(Window)
  194.             HandleEvents(Window);
  195.  
  196.     myError(NULL,10);
  197. }
  198.  
  199. /* ENDE */
  200.  
  201.  
  202.